package cn.wolfcode.trip.base.util;

import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

/*
* 用户上下文工具类:作用把用户存入Session
*                从Session中拿到登录的用户
* */
public class UserContext {
    public static HttpSession getSession(){
        return ((ServletRequestAttributes)(RequestContextHolder.getRequestAttributes()))
                .getRequest().getSession();
    }
    public static void setCurrentUser(User user){
        getSession().setAttribute("USER_IN_SESSION",user);
    }
    public static User getCurrentUser(){
        return (User) getSession().getAttribute("USER_IN_SESSION");
    }
}
